<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>   
<%@ include file="/page/base.jsp"%>
<link href="<%=path%>/manage/css/uploadify.css" rel="stylesheet" type="text/css" />
<script language="javascript"  src="<%=path%>/manage/js/swfobject.js"></script>
<script language="javascript"  src="<%=path%>/manage/js/jquery.uploadify.v2.1.0.min.js"></script>
<script language="javascript"  src="<%=path%>/manage/js/jquery.cookie.js"></script>
  
    <script type="text/javascript"> 
     function showResult(){//删除显示的上传成功结果   
          $("#result").html("");   
        }   
    
    $(document).ready(function() {
    	var datas = new Array();
    	var resumeType = "${param.type}";
    	var isMulti = "${param.multi}";
    	var callback = "${param.callback}";
    	var type = resumeType;
    	var btnText;
    	var format;
    	if ( resumeType == 2 ) {
    		resumeType="*.mp3";
    		format="mp3";
    		btnText="点击选择音频";
    	}else if( resumeType == 3 || resumeType == 4){
    		resumeType="*.mp4";
    		format="mp4";
    		btnText="点击选择视频";
    	} else if (resumeType == 5) {
    		resumeType="*.jpg,*.png";
    		format="jpg,png";
    		btnText="点击选择图片";
    	}
        $('#fileInput').uploadify({   
 		'uploader': root+'/manage/swf/uploadify.swf',
        'script': root+'/upload/uploadFile.action'+';jsessionid=' + $.cookie('JSESSIONID'),   //指定服务端处理类的入口
        'scriptData':{'t':type},
        'folder': 'uploadFile',
        //'fileDesc': format, //设置文件格式
        'fileExt': resumeType, //设置文件后缀
 		'cancelImg': root+'/manage/images/cancel.png',
        'fileDataName': 'fileInput', //和input的name属性值保持一致就好，Struts2就能处理了   
        'queueID': 'fileQueue',   
        'auto': false,//是否选取文件后自动上传   
        'multi': isMulti,//是否支持多文件上传
        'simUploadLimit' : 100,//每次最大上传文件数   
        'buttonText': btnText,//按钮上的文字   
        'displayData': 'percentage',//有speed和percentage两种，一个显示速度，一个显示完成百分比    
        'onSelect': function(event, queueID, fileObj){
        	if(!contains(resumeType,fileObj.type,true) ){
				$("#uploadbtn").attr("href","#");
				alert(fileObj.name+"上传文件格式必须为:"+format);
				return false;
			} else {
				$("#uploadbtn").attr("href","javascript:$('#fileInput').uploadifyUpload();");
			}
        	//$("#fileQueue").html("");
        },
        'onComplete': function (event, queueID, fileObj, response, data){ 
                  datas.push(response);
          },
        'onAllComplete': function(event,data) {
        	var count="${param.imgIdCount}";
            if(count >= 0 ) {
            	for (var i=0;i<datas.length;i++){
            		eval(callback+"('"+datas[i]+"',"+count+")");
            	}
            } else {
            	for (var i=0;i<datas.length;i++){
            		eval(callback+"('"+datas[i]+"')");
            	}
            }
            datas.length=0;
          }
           
        });  
           
    });  
    
    function contains(string,substr,isIgnoreCase)
	{
		if(isIgnoreCase)
		{
		 string=string.toLowerCase();
		 substr=substr.toLowerCase();
		}
		 var startChar=substr.substring(0,1);
		 var strLen=substr.length;
			 for(var j=0;j<string.length-strLen+1;j++)
			 {
				 if(string.charAt(j)==startChar)//如果匹配起始字符,开始查找
				 {
					   if(string.substring(j,j+strLen)==substr)//如果从j开始的字符与str匹配，那ok
					   {
							 return true;
					   }  
				 }
			 }
			 return false;
	}

</script>   
  	<input type="file" name="fileInput" id="fileInput" />  &nbsp;&nbsp;&nbsp;&nbsp; 
  	<script type="text/javascript">
  		var isMulti = "${param.multi}";
  		if(isMulti=='true')
  			$("#multiTip").html("按住ctrl可以多选图片");
	</script>
	<span id="multiTip"></span>
    <div id="result"></div> 
    <div id="fileQueue"></div> 
    <a href="javascript:$('#fileInput').uploadifyUpload();" id="uploadbtn" style="text-decoration:none;" >开始上传</a>
